package com.bwie.es.synchronization;


import com.alibaba.fastjson.JSON;
import com.bwie.common.domain.request.ProductRequest;
import com.bwie.common.result.Result;
import com.bwie.es.feign.ShowFeignController;
import com.bwie.es.service.EsService;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import java.util.List;


/**
 * 项目启动把商品同步到ES索引库当中
 */
@Component
public class Sysc implements ApplicationRunner{
    @Autowired
    private EsService esService;
    @Autowired
    private ShowFeignController feignController;

    @Override
    public void run(ApplicationArguments args) throws Exception {;
        esService.deleteCourseEs();
        Result<List<ProductRequest>> result = feignController.showAll();
        List<ProductRequest> list = result.getData();
        JSON.toJSONString(list);
        esService.insertBatch(list);
    }
}
